<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div><input type="text">+
    <input type="text"> <button id="deng">=</button>  <span id="he">？</span>
    </div>
   
</body>
<script>
    var ipt=document.getElementsByTagName('input')

        var d=document.getElementById('deng')
        var he=document.getElementById('he')
        for(var i=0;i< ipt.length-1;i++){
            ipt[i].onkeydown=function(){
                this.value=this.value.replace(/[^\d]/,'')
              
            }

        }
        d.onclick=function(){
            if(ipt[0].value!=''&&ipt[1].value!=''){
                he.innerHTML=parseInt(ipt[0].value)+parseInt(ipt[1].value)
            }else{
                alert('请输入数字')
            }
        }
</script>
</html>